<?	/*
	// File:	index.php
	// Purpose:	Includes, Coordinate.
	// Creation:	2001-10-29
	// Author:	Felix <webmaster@can-host.com>
	*/
// Turn off default error reporting
//error_reporting(0);
error_reporting(E_ALL & ~E_NOTICE);
ob_start();

//
// include configuration & functions file & error handling
if (!isset($cfg) || $cfg['httpd_mode'] == 'apache') {
	$tmp = "config.inc.php";
	include($tmp);

	$tmp = "functions.inc.phps";
	include($tmp);
}

$tmp = 'rpc.inc.phps';
include_once($tmp);

load_globals();

load_modules();

$newcfg = array();
call_hook('web:cfg:default', $newcfg);
//$cfg += $newcfg;
array_concat($cfg, $newcfg, false);
call_hook('web:cfg:set', $cfg);

/*//
// Shoot out NO-CACHE to proxies
send_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
send_header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
send_header("Cache-Control: no-store, no-cache, must-revalidate");
send_header("Cache-Control: post-check=0, pre-check=0", false);
send_header("Pragma: no-cache");*/

// For some reason we get blank lines sometimes
ob_clean();

send_header('Content-Type: text/xml');

// 'dynamic' GLOBAL vars declared.
global $T, $userdata, $cfg, $logged_id;

load_cached_file('lang/english.phps', 'T');

//
// Initialize certain general vars.
$userdata = array();
$logged_id = false;

unset($personaldata);
unset($domaindata);
unset($resellerdata);
unset($error);
unset($notice);
//

//
// Initialize
//
// Disable register_globals to ensure security
ini_set('register_globals', '0');

// Set magic quotes runtime off (dont quote MySQL data)
set_magic_quotes_runtime(0);

// Ignore user abort, 60 seconds max allowed to a web interface script.
if ($cfg['httpd_mode'] == 'apache') {
	ignore_user_abort();
}

//
// Setup Database Connection
@mysql_connect($cfg['dbhost'], $cfg['dbuser'], $cfg['dbpass']);
@mysql_select_db($cfg['dbname']);

if(!is_enabled('ext.mod.phps')) {
	XMLRPC_error(5000, 'Service disabled');
	return;
}

unset($request);
if(isset($_REQUEST['q'])) {
	$request = $_REQUEST['q'];
} elseif(isset($_SERVER['HTTP_RAW_POST_DATA'])) {
	$request = $_SERVER['HTTP_RAW_POST_DATA'];
}

if(isset($request)) {
	$xml = XMLRPC_parse($request);
	$request_method = XMLRPC_getMethodName($xml);
	$params = XMLRPC_getParams($xml);

	$request_session = '';
	$request_data = array();
	rpc_decode_params($params, $request_session, $request_data);

} else {
	$request_method = load_input_vars('method');
	$request_session = load_input_vars('session');
	$request_data = load_input_vars('data');
	if($request_method===null) {
		XMLRPC_error(4000, 'No methodCall specicified');
		return;
	}
}

clean_input_vars($request_data);
clean_input_vars($request_session);

$result = rpc_handle_method($request_method, $request_data, $request_session);

if(rpc_is_error($result))
	XMLRPC_error($result['data'][0], $result['data'][1]);
else
	XMLRPC_response(XMLRPC_prepare($result['data']));

// THE END
return;
?>
